package com.chuangke.fss;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.chuangke.common.exception.ChuangkeException;
import com.chuangke.common.utils.SpringContextUtil;
import com.chuangke.fss.disk.FSSDisk;
import com.chuangke.fss.fastdfs.FSSFastDfs;
import com.chuangke.fss.minio.FSSMinIO;

@Component
public class FSSClient {

	@Autowired
	private FSSConfig fssConfig;

	public FSS getDefaultFss() {
		return getFss(fssConfig.getStorageType());
	}
	
	public FSS getFss(String storageType) {
		if("disk".equals(storageType)) {
			return getDiskFss();
		}else if("fastdfs".equals(storageType)) {
			return getFastDfsFss();
		}else if("minio".equals(storageType)) {
			return getMinio();
		}else {
			throw new ChuangkeException("暂不支持文件存储类型" + storageType);
		}
	}
	
	public FSS getDiskFss() {
		return SpringContextUtil.getBean(FSSDisk.class);
	}
	
	public FSS getMinio() {
		return SpringContextUtil.getBean(FSSMinIO.class);
	}

	public FSS getFastDfsFss() {
		return new FSSFastDfs();
	}
	
	public String getDefaultStorageType() {
		return fssConfig.getStorageType() ;
	}
}
